package com.gxa.www.cl.controller;

import com.gxa.www.cl.common.base.RespResult;
import com.gxa.www.cl.domain.entity.Admin;
import com.gxa.www.cl.service.UpdateUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class PasswordController {

    @Autowired
    private UpdateUserService updateUserService;

    @PostMapping("/updatePassword")
    public RespResult updatePassword(@RequestBody Admin request) {
        String username = request.getUser_name();
        String newPassword = request.getNewPassword();

        // 更新密码
        boolean isUpdated = updateUserService.updatePassword(username, newPassword);
        if (isUpdated) {
            return RespResult.success("密码更新成功");
        } else {
            return RespResult.error("密码更新失败");
        }
    }
}
